/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tamnhat.controller;

import com.tamnhat.entity.MediaItem;
import com.tamnhat.model.GameAndroidModel;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.servlet.ServletContext;

/**
 *
 * @author Administrator
 */
@SessionScoped
public class AndroidController implements Serializable {

    private int itemId;
    private String titleVn;
    private String titleEn;
    private String descriptionVn;
    private String preview;
    private String downloadLink;
    private String handset;
    private DataModel items = null;
    private MediaItem current;
    private List<MediaItem> listTable = new ArrayList<MediaItem>();
    private boolean finish = false;

    /**
     * Creates a new instance of AndroidController
     */
    public AndroidController() {
        try {
            listTable = GameAndroidModel.getListCondition(20, "");
            items = new ListDataModel(listTable);
        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("ERROR: " + e.getMessage()));
            e.printStackTrace();
        }
    }

    public boolean isFinish() {
        return finish;
    }

    public void setFinish(boolean finish) {
        this.finish = finish;
    }

    public MediaItem getCurrent() {
        return current;
    }

    public void setCurrent(MediaItem current) {
        this.current = current;
    }

    public DataModel getItems() {
        return items;
    }

    public void setItems(DataModel items) {
        this.items = items;
    }

    public int getItemId() {
        return itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }

    public String getTitleVn() {
        return titleVn;
    }

    public void setTitleVn(String titleVn) {
        this.titleVn = titleVn;
    }

    public String getTitleEn() {
        return titleEn;
    }

    public void setTitleEn(String titleEn) {
        this.titleEn = titleEn;
    }

    public String getDescriptionVn() {
        return descriptionVn;
    }

    public void setDescriptionVn(String descriptionVn) {
        this.descriptionVn = descriptionVn;
    }

    public String getPreview() {
        return preview;
    }

    public void setPreview(String preview) {
        this.preview = preview;
    }

    public String getDownloadLink() {
        return downloadLink;
    }

    public void setDownloadLink(String downloadLink) {
        this.downloadLink = downloadLink;
    }

    public String getHandset() {
        return handset;
    }

    public void setHandset(String handset) {
        this.handset = handset;
    }

    public String viewDetail() {
        current = (MediaItem) items.getRowData();
        return "viewDetail?faces-redirect=true";
    }

    public String moreGame() {
        try {
            int size = listTable.size();
            List<MediaItem> list = GameAndroidModel.getListCondition(10, listTable.get(size - 1).getItemId());
            if (list.size() < 10) {
                finish = true;
            }
            for (int i = 0; i < list.size(); i++) {
                listTable.add(list.get(i));
            }
            items = new ListDataModel(listTable);
        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("ERROR: " + e.getMessage()));
            e.printStackTrace();
        }
        return "";
    }

    public String check() {
        return "";
    }
}
